package com.ofek.eventos.serverside.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DatabaseHandler {
	public String useQuery;
	private final String connectURL;
	public Object login(final String uid, final String pw) throws SQLException {
		Statement stmt = null;
		final String query = "select uid,fname,lname,tid "
				+ "from Users where uid=\"" + uid + "\""
				+ " and password=\"" + pw + "\"";
		ResultSet rs = null;
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(connectURL);
			stmt = conn.createStatement();
			stmt.execute(useQuery);
			rs = stmt.executeQuery(query);
			if (!rs.next())
				return null;
			return null;
		} catch (final SQLException e) {
			e.printStackTrace();
		} finally {
			if (rs != null)
				rs.close();
			if (stmt != null) {
				stmt.close();
			}
			if (conn != null)
				conn.close();
		}
		return null;
	}
	public DatabaseHandler(final String ip,final String username,final String password,final String dbName) {
		connectURL="jdbc:mysql://"+ip + ":3306/?user="+username + "&password="+password;
		useQuery = "USE " + dbName;
	}
}
